var path = require('path');
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');


var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'src');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');

module.exports = {
  devtool: 'eval-source-map',
  entry: './src/routers.js',
  output: {
    path: path.resolve(__dirname, './build'),
    filename: 'bundle.js',
    chunkFilename: "[name].bundle.js"
  },
  //添加我们的插件 会自动生成一个html文件
  plugins: [
    new HtmlwebpackPlugin({  // Also generate a test.html
      title: '爱租派',
      template: 'src/index.html'
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: true
      },
      output: {
        comments: false,
      }
    })

  ],
  resolve:{
    extensions:['', '.js', '.jsx']
  },

  module:{
    //用它来处理各种类型的文件
    loaders: [
      // css-loader 和 style－loader，css-loader会遍历css文件，找到所有的url(...)并且处理。
      // style-loader会把所有的样式插入到你页面的一个style tag中
      // loaders中规则的执行顺序是从右到左，先css，再style，如果有sass，则应该是['style', 'css', 'sass']
      {
        test: /\.css$/,
        loader: 'style!css',
      },
      //处理图片和其他静态文件
      {
        test: /\.(jpe?g|png|gif|svg)$/,
        loader: 'url?limit=1024',
        include: APP_PATH
      },
      //支持es6语法
      {
        test: /\.jsx?$/,
        loader: 'babel',
          query: {
              presets: ['react', 'es2015', 'stage-0']
          },
        include: APP_PATH,
      },
      //支持es6语法
      {
        test: /\.js$/,
        loader: 'babel',
          query: {
              presets: ['react', 'es2015', 'stage-0']
          },
        include: APP_PATH,
      },

    ],
  }

}